<?php

class HotspotController extends AppController
{
	/**
	 * @var string the default layout for the views. Defaults to '//layouts/column2', meaning
	 * using two-column layout. See 'protected/views/layouts/column2.php'.
	 */
	
	public function actionIndex()
	{
		$this->render('index');
	}
	
	public function actionAdd()
	{
		//print_r($_POST);

// 		$this->renderPartial('add');
	}
	
	public function actionAdd2()
	{
		$username =	 $_POST['usename'];
		$password =	 $_POST['password'];
		$bytein = 	$_POST['bytein'];
		$byteout =	 $_POST['byteout'];
		$bytetotal=	 $_POST['bytetotal'];
		$uptime= $_POST['uptime'];
		require_once('routeros_api.class.php');
		$API = new routeros_api();
	
		if ($API->connect('192.168.88.1', 'admin', '')) {
			print_r($API->comm("/ip/hotspot/user/add", array(
					"name"     =>$username,
					"password" =>$password,
					"limit-bytes-in"  =>$bytein,
					"limit-bytes-out"  =>$byteout,
					"limit-bytes-total"  =>$bytetotal,
					"limit-uptime"  =>$uptime,
			)));
			echo "Add user".$username;
			//  $API->read(false);
			//  $ARRAY = $API->parse_response($READ);
		
			// echo "<pre>";print_r($ARRAY);echo "</pre>";
		
			$API->disconnect();
		
		}
		
		
// 		$this->renderPartial('add2');
		
	}
	
	public function actionBatchadd()
	{
		//print_r($_POST);
	
		$this->render('batchadd');
	}
	
	public function actionBatchsubmit()
	{
		$number_user =	 $_POST['number_user'];
		$prefix =	 $_POST['prefix'];
		$name_length = 	$_POST['name_length'];
		$pass_length =	 $_POST['pass_length'];
		$bytein = 	$_POST['bytein'];
		$byteout =	 $_POST['byteout'];
		$bytetotal=	 $_POST['bytetotal'];
		$uptime= $_POST['uptime'];
		$username = $prefix.rand(10,100);
		$password = rand(10,100);
		require_once('routeros_api.class.php');
		$API = new routeros_api();
		if ($API->connect('192.168.88.1', 'admin', '')) {
			
			for($i=0;$i<=$number_user;$i++){
				$username = $prefix.rand(10,100);
				$password = rand(10,100);
			$API->comm("/ip/hotspot/user/add", array(
					"name"     =>$username,
					"password" =>$password,
					"limit-bytes-in"  =>$bytein,
					"limit-bytes-out"  =>$byteout,
					"limit-bytes-total"  =>$bytetotal,
					"limit-uptime"  =>$uptime,
			));
			echo $username."<br>";
			}
			//  $API->read(false);
			//  $ARRAY = $API->parse_response($READ);
	
			// echo "<pre>";print_r($ARRAY);echo "</pre>";
	
			$API->disconnect();
			
		//echo "scc".$number_user;
	
		}
	
	
// 		$this->renderPartial('add2');
	
	}
	
	public function actionCallUser()
	{
		$this->renderPartial('CallUser');
	}
	
	public function actionCallActiveuser()
	{
		$this->renderPartial('Callactiveuser');
	}
}
